package com.societyGames.catExercises
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextLineMetrics;

	public class SurplusDisplay extends Sprite
	{
		private var _textField:TextField;
		private var _displayObject:DisplayObject;
		
		public function SurplusDisplay(displayObject:DisplayObject)
		{
			this._displayObject = displayObject;
			this.addChild(this._displayObject);

			this._textField = new TextField();
			this.addChild(this._textField);
		}
		
		public function set count(value:int):void
		{	
			this._textField.text = "+" + value.toString();
			//Measure the text.
			var metrics:TextLineMetrics = this._textField.getLineMetrics(0);
			this._textField.width = metrics.width + 4;
			this._textField.height = metrics.height + 4;		
			this._textField.x = 0;
			this._textField.y = 0;
			//Move the displayObject to correct X position.
			this._displayObject.x = this._textField.width + 2;
			this._displayObject.y = 0;			
			//Center everything
			var maxHeight:Number = this.height;
			this._textField.y = int((maxHeight - this._textField.height) / 2);
			this._displayObject.y = int((maxHeight - this._displayObject.height) / 2);
		}
	}
}